home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
UPC12BS1.ZIP
/
MAIL
/
MLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-20
|
15KB
|
436 lines
/*--------------------------------------------------------------------*/
/* m l i b . c */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by */
/* the UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: mlib.c 1.6 1993/09/20 04:39:51 ahd Exp $
*
* Revision history:
* $Log: mlib.c $
* Revision 1.6 1993/09/20 04:39:51 ahd
* OS/2 2.x support
*
* Revision 1.5 1993/08/11 02:31:12 ahd
* Use standard denormalize() macro for slash --> back slashes
*
* Revision 1.4 1993/08/03 03:11:49 ahd
* Further Windows 3.x fixes
*
* Revision 1.3 1993/07/31 16:26:01 ahd
* Changes in support of Robert Denny's Windows support
*
*
* 13 May 89 Use PC format path names for editor
* 01 Oct 89 Make Console_fgets use far pointers
* Alter Console_fgets and Is_Console to type boolean
*
* 29 Jul 90 Use PC format path names for pager
*/
/*
ibmpc/mlib.c by <skl@van-bc.UUCP> August/87
Mailer UA system-dependent library
Services to provide in mlib.c:
Get a single character from the console.
Invoke the local editor on a given file.
Determine if a given file stream points to the console.
Get a line from the console.
Invoke a local pager on a given file.
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <io.h>
#include <dos.h>
#if defined(WIN32)
#include <windows.h>
#endif
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "hlib.h"
#include "execute.h"
/*--------------------------------------------------------------------*/
/* Set up for console services */
/*--------------------------------------------------------------------*/
#if defined(FAMILYAPI) || defined(BIT32ENV) || defined(_Windows)
#define SIMPLE_CONSOLE_FGETS
#else
#define MULTIPLEX 0x2f /* 8086 DOS Interrupt for multiplexing */
static int DOSRead( char *buff, const int buflen);
static boolean DOSKeyActive( void );
static int DOSKeyRead( char *buff , int buflen );
#endif
/*--------------------------------------------------------------------*/
/* G e t _ O n e */
/* */
/* Get a single character from the console */
/*--------------------------------------------------------------------*/
int Get_One()
{
return getch();
} /*Get_One*/
/*--------------------------------------------------------------------*/
/* I n v o k e */
/* */
/* Invoke the user's editor or pager to handle a text file */
/*--------------------------------------------------------------------*/
int Invoke(const char *ecmd, const char *filename)
{
char command[FILENAME_MAX*2 + 1];
char tempname[FILENAME_MAX];
if (ecmd == nil(char))
{
printf("Invoke: No program specified to invoke.\n");
return 1;
}
strcpy(tempname,filename);
denormalize( tempname );
sprintf(command, ecmd, tempname);
if(executeCommand(command, NULL, NULL, TRUE, TRUE ) != 0)
{
printf("Invoke: \"%s\" failed.\n", command);
return(2);
}
return 0;
} /* Invoke */
/*--------------------------------------------------------------------*/
/* I s _ C o n s o l e */
/* */
/* Determine if stream is from the console */
/* */
/* Note: isatty() actually returns if the stream is a */
/* character device, thus causing device NUL to appear */
/* interactive; this is not acceptable, but there is not a */
/* trivial fix. */
/*--------------------------------------------------------------------*/
boolean Is_Console(FILE *stream)
{
return isatty(fileno(stream));
} /*Is_Console*/
#ifdef SIMPLE_CONSOLE_FGETS
/*--------------------------------------------------------------------*/
/* C o n s o l e _ f g e t s */
/* */
/* Read a full line from the console under non-DOS systems */
/*--------------------------------------------------------------------*/
boolean Console_fgets(char *buff, int buflen, char *prompt)
{
if (bflag[F_DOSKEY] )
{
printmsg(0,"DOSKEY support not available, option disabled");
bflag[F_DOSKEY] = FALSE;
}
fputs(prompt, stdout);
return (fgets(buff, buflen, stdin) != nil(char)) ? TRUE : FALSE;
} /*Console_fgets*/
#else
/*--------------------------------------------------------------------*/
/* C o n s o l e _ f g e t s */
/* */
/* Get a line of input from the local console */
/* */
/* This is a hook to allow for using the local system's */
/* facility for input line editing. We call DOS to perform */
/* a line read, thus allowing utilities like DOSEDIT or CED */
/* to do their fancy work. */
/*--------------------------------------------------------------------*/
boolean Console_fgets(char *buff, int buflen, char *prompt)
{
static boolean eof = FALSE; /* pending EOF flag */
char *eofptr;
if (eof) { /* have a pending EOF? */
eof = FALSE; /* no more pending EOF */
return FALSE; /* signal the EOF */
}
/*--------------------------------------------------------------------*/
/* Prompt the user, read the data, and then go to a new line */
/*--------------------------------------------------------------------*/
fputs(prompt, stdout);
if ( DOSKeyActive() )
buflen = DOSKeyRead( buff, buflen );
else
buflen = DOSRead( buff, buflen );
putchar('\n');
/*--------------------------------------------------------------------*/
/* Determine if we hit end of file on the read */
/*--------------------------------------------------------------------*/
if ( buflen == -1 )
{
*buff = '\0';
return FALSE;
}
/*--------------------------------------------------------------------*/
/* Terminate the buffer */
/*--------------------------------------------------------------------*/
buff[buflen